package work810;

import java.util.Random;
import java.util.Scanner;

public class work1 {
  static Scanner sc = new Scanner(System.in);

  public void login() {
    System.out.println("请输入用户名：");
    String userName = sc.next();
    System.out.println("请输入密码：");
    String passWord = sc.next();
    String verCode ="";
    int ii = 0;
    while (ii < 4) {
      Random random = new Random();
      int i = random.nextInt(123);
      if (i >= 65 && i <= 90) {
        verCode = verCode + (char)i;
        ii++;
      }else
      if (i >= 97 && i <= 122) {
        verCode = verCode + (char)i;
        ii++;
      }else
      if (i >= 0 && i < 10) {
        String b = random + "";
       verCode = verCode + b.charAt(0);
        ii++;
      }
    }
    System.out.println(verCode);
   verify(userName,passWord,verCode);

  }

  public boolean verCode(String str, String verCode) {
    if (str.length() == 4) {
      if (str.equals(verCode)) {
        return true;
      }
    }
    return false;
  }

  public void verify(String userName,String passWord,String verCode){
    System.out.println("请输验证码：");
    String str = sc.next();
    if (userName.equals("admin") && passWord.equals("password") &&verCode(str, verCode)){
      System.out.println("验证通过，请使用本系统");
    }else {
      System.out.println("验证未通过，拒绝使用");
    }
  }

  public static void main(String[] args) {
    work1 work1 = new work1();
    work1.login();
  }
}
